<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册 - 宠物医院管理系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: 'Microsoft YaHei', sans-serif;
            padding: 20px 0;
        }
        .register-container {
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            padding: 40px;
            width: 100%;
            max-width: 500px;
            backdrop-filter: blur(10px);
        }
        .register-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .register-header h2 {
            color: #333;
            font-weight: 600;
            margin-bottom: 10px;
        }
        .register-header p {
            color: #666;
            font-size: 14px;
        }
        .form-floating {
            margin-bottom: 20px;
        }
        .form-control {
            border: 2px solid #e9ecef;
            border-radius: 10px;
            padding: 12px 15px;
            transition: all 0.3s ease;
        }
        .form-control:focus {
            border-color: #667eea;
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        .btn-register {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: none;
            border-radius: 10px;
            padding: 12px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1px;
            transition: all 0.3s ease;
        }
        .btn-register:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
        }
        .alert {
            border-radius: 10px;
            border: none;
            margin-bottom: 20px;
        }
        .login-link {
            text-align: center;
            margin-top: 20px;
        }
        .login-link a {
            color: #667eea;
            text-decoration: none;
            font-weight: 500;
        }
        .login-link a:hover {
            text-decoration: underline;
        }
        .logo {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 20px;
            color: white;
            font-size: 24px;
        }
        .password-strength {
            font-size: 12px;
            margin-top: 5px;
        }
        .strength-weak { color: #dc3545; }
        .strength-medium { color: #ffc107; }
        .strength-strong { color: #28a745; }
    </style>
</head>
<body>
    <div class="register-container">
        <div class="register-header">
            <div class="logo">
                <i class="fas fa-paw"></i>
            </div>
            <h2>用户注册</h2>
            <p>创建您的宠物医院管理系统账号</p>
        </div>

        <!-- 显示错误信息 -->
        <c:if test="${not empty error}">
            <div class="alert alert-danger" role="alert">
                <i class="fas fa-exclamation-circle me-2"></i>${error}
            </div>
        </c:if>

        <!-- 注册表单 -->
        <form action="${pageContext.request.contextPath}/user/register" method="post" id="registerForm">
            <input type="hidden" name="action" value="register">
            
            <div class="row">
                <div class="col-md-6">
                    <div class="form-floating">
                        <input type="text" class="form-control" id="username" name="username" 
                               placeholder="请输入用户名" required maxlength="50" value="${param.username}">
                        <label for="username"><i class="fas fa-user me-2"></i>用户名</label>
                        <div class="form-text">用户名将用于登录，不可修改</div>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-floating">
                        <input type="text" class="form-control" id="realName" name="realName" 
                               placeholder="请输入真实姓名" required maxlength="50" value="${param.realName}">
                        <label for="realName"><i class="fas fa-id-card me-2"></i>真实姓名</label>
                    </div>
                </div>
            </div>

            <div class="form-floating">
                <input type="password" class="form-control" id="password" name="password" 
                       placeholder="请输入密码" required minlength="6" maxlength="20">
                <label for="password"><i class="fas fa-lock me-2"></i>密码</label>
                <div id="passwordStrength" class="password-strength"></div>
            </div>

            <div class="form-floating">
                <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" 
                       placeholder="请确认密码" required minlength="6" maxlength="20">
                <label for="confirmPassword"><i class="fas fa-lock me-2"></i>确认密码</label>
            </div>

            <div class="row">
                <div class="col-md-6">
                    <div class="form-floating">
                        <input type="tel" class="form-control" id="phone" name="phone" 
                               placeholder="请输入手机号码" pattern="^1[3-9]\d{9}$" value="${param.phone}">
                        <label for="phone"><i class="fas fa-phone me-2"></i>手机号码</label>
                    </div>
                </div>
                <div class="col-md-6">
                    <div class="form-floating">
                        <input type="email" class="form-control" id="email" name="email" 
                               placeholder="请输入邮箱" maxlength="100" value="${param.email}">
                        <label for="email"><i class="fas fa-envelope me-2"></i>邮箱</label>
                    </div>
                </div>
            </div>

            <div class="form-floating">
                <textarea class="form-control" id="address" name="address" 
                          placeholder="请输入地址" style="height: 80px" maxlength="200">${param.address}</textarea>
                <label for="address"><i class="fas fa-map-marker-alt me-2"></i>地址</label>
            </div>

            <div class="d-grid">
                <button type="submit" class="btn btn-primary btn-register">
                    <i class="fas fa-user-plus me-2"></i>注册
                </button>
            </div>
        </form>

        <div class="login-link">
            <p>已有账号？<a href="${pageContext.request.contextPath}/pages/common/login.jsp">立即登录</a></p>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 密码强度检测
        document.getElementById('password').addEventListener('input', function() {
            const password = this.value;
            const strengthDiv = document.getElementById('passwordStrength');
            
            if (password.length === 0) {
                strengthDiv.innerHTML = '';
                return;
            }
            
            let strength = 0;
            if (password.length >= 6) strength++;
            if (password.match(/[a-z]/)) strength++;
            if (password.match(/[A-Z]/)) strength++;
            if (password.match(/[0-9]/)) strength++;
            if (password.match(/[^a-zA-Z0-9]/)) strength++;
            
            if (strength < 2) {
                strengthDiv.innerHTML = '<span class="strength-weak">密码强度：弱</span>';
            } else if (strength < 4) {
                strengthDiv.innerHTML = '<span class="strength-medium">密码强度：中</span>';
            } else {
                strengthDiv.innerHTML = '<span class="strength-strong">密码强度：强</span>';
            }
        });

        // 表单验证
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            const password = document.getElementById('password').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
            
            if (password !== confirmPassword) {
                e.preventDefault();
                alert('两次输入的密码不一致');
                document.getElementById('confirmPassword').focus();
                return;
            }
            
            const phone = document.getElementById('phone').value;
            if (phone && !/^1[3-9]\d{9}$/.test(phone)) {
                e.preventDefault();
                alert('手机号码格式不正确');
                document.getElementById('phone').focus();
                return;
            }
        });

        // 自动清除提示信息
        setTimeout(function() {
            const alerts = document.querySelectorAll('.alert');
            alerts.forEach(function(alert) {
                alert.style.transition = 'opacity 0.5s';
                alert.style.opacity = '0';
                setTimeout(function() {
                    alert.remove();
                }, 500);
            });
        }, 5000);
    </script>
</body>
</html>
